<template>
  <view
    :style="[windowHeight]"
    class="flex justify-center items-center text-gray-600"
  >
    登录中...
  </view>
</template>

<script setup lang="ts">
import { login } from "@/api/user";
import { saveTokenSync, setLoginedData } from "@/utils/auth";
import useLoginedData from "@/hooks/useLoginedData";
import { useUserStore } from "@/stores/user";
import useStyles from "@/hooks/useStyle";
const { windowHeight } = useStyles();
const { runAsync } = useLoginedData();
const userStore = useUserStore();

onLoad(async (options: any) => {
  try {
    const data = await login({ username: "1929100001", password: "123456" });
    saveTokenSync(data.token);
    const res = await runAsync();
    userStore.setUserStoreData(toRaw(res));
    setLoginedData(JSON.stringify(toRaw(res)));
    uni.redirectTo({
      url: "/pages/index/index",
    });
  } catch (e) {
    //TODO handle the exception
  } finally {
  }
});
</script>

<style lang="scss" scoped>
// @import url("~@/uni.scss");
</style>
